/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package buildyourtruck;

import javax.swing.JOptionPane;

/**
 * User interface to build a truck.
 *
 * @author jonesbr
 */
public class BuildYourTruck {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        promptUser();
    }

    public static void promptUser() {
        // create a new Truck object, and store it in a varaible of type Truck, named myTruck.
        Truck myTruck = new Truck();

        String[] allCabs = {"Regular", "Access", "Double"};
        Object objCabChoice = JOptionPane.showInputDialog(null, "What cab do you want?", "Select a Cab", JOptionPane.QUESTION_MESSAGE, null, allCabs, "Double");
        String cabChoice = objCabChoice.toString();
        System.out.println("cabChoice: " + cabChoice);

        String[] allDriveTrains = new String[3];
        allDriveTrains[0] = "4x2";
        allDriveTrains[1] = "4x2 PreRunner";
        allDriveTrains[2] = "4x4";
        Object objDriveTrain = JOptionPane.showInputDialog(null, "What drive train?", "Select a Drive Train", JOptionPane.QUESTION_MESSAGE, null, allDriveTrains, allDriveTrains[2]);
        String driveTrain = objDriveTrain.toString();

        // compare the cab type and the drive train to see if they are compatible.  Show a warning if they are not, and reprompt.
        if (cabChoice.equalsIgnoreCase("Regular")) {
            if (driveTrain.equals(allDriveTrains[1])) {
                // send a warning.  No can do.
                JOptionPane.showMessageDialog(null, "Regular and " + allDriveTrains[1] + " are not compatible.  Please make another selection");
            } else {
                // set the cab type and drive train on our truck object.
                myTruck.setCabType(cabChoice);
                myTruck.setDriveTrain(driveTrain);
                
            }
        } else if (cabChoice.equalsIgnoreCase("Double") && driveTrain.equals(allDriveTrains[0])) {
            JOptionPane.showMessageDialog(null, "Double cab and " + allDriveTrains[0] + " are not compatible.  Please make another selection");
        } else if (cabChoice.equalsIgnoreCase("Access") && (driveTrain.equals(allDriveTrains[0]) || driveTrain.equals(allDriveTrains[1]))) {
            JOptionPane.showMessageDialog(null, "Access cab and " + driveTrain + " are not compatible.  Please make another selection");
        } else {
            myTruck.setCabType(cabChoice);
            myTruck.setDriveTrain(driveTrain);
        }
        
        System.out.println(myTruck.toString());
    }
}
